package com.QiHunCn.app;

import android.app.Activity;
import android.media.SoundPool;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import java.util.HashMap;
import android.media.AudioManager;


public class MainActivity extends Activity implements PlaceholderFragment.OnPlaceholderFragmentButtomClickListener{
    private final static String LOG_TAG = "QiHunCn-LOG-TAG";
    public final static int SOUNDPOOL_MAX_STREAM_NUM = 5;
    private SoundPool mSndPool;
    private HashMap<String, Integer> sndMap = new HashMap<String, Integer>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mSndPool = new SoundPool(SOUNDPOOL_MAX_STREAM_NUM, AudioManager.STREAM_MUSIC, 0);
        sndMap.put("Next", mSndPool.load(this, R.raw.select, 1));
        sndMap.put("Pre", mSndPool.load(this, R.raw.piecedrop, 1));


        if (savedInstanceState == null) {
            getFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment())
                    .commit();
        }
    }

    @Override
    public void OnPlaceholderFragmentButtomClicked(Integer id) {
//        PlaceholderFragment fragment = (PlaceholderFragment) getFragmentManager().findFragmentById(R.id.container);

        switch (id)
        {
            case R.id.imageButtonPre:
                mSndPool.play(sndMap.get("Pre"),1,1,0,0,1);
                break;
            case R.id.imageButtonNext:
                mSndPool.play(sndMap.get("Next"),1,1,0,0,1);
                break;
            default:
                Log.d(LOG_TAG, "no id comes from OnPlaceholderFragmentButtomClicked()");
                break;
        };

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

